var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
  usePageLifecycle: () => usePageLifecycle
});
module.exports = __toCommonJS(stdin_exports);
var import_uni_app = require("@dcloudio/uni-app");
var import_vue = require("vue");
const usePageLifecycle = () => {
  const _this = (0, import_vue.getCurrentInstance)();
  const findPage = (tt) => {
    if (!tt || tt.proxy.mpType === "page")
      return tt;
    return findPage(tt.parent);
  };
  const pageScrollTo = (opt) => {
    uni.pageScrollTo(opt);
  };
  const onPageShow = (hook) => {
    if (!hook)
      return;
    (0, import_vue.onMounted)(() => {
      const page = findPage(_this);
      hook();
      if (Array.isArray(page.onShow)) {
        page.onShow.push(hook);
      } else {
        page.onShow = [hook];
      }
    });
    return;
    (0, import_vue.onMounted)(() => {
      hook && hook();
    });
    (0, import_uni_app.onShow)(hook);
  };
  const onPageReachBottom = (hook) => {
    if (!hook)
      return;
    (0, import_vue.onMounted)(() => {
      const page = findPage(_this);
      if (Array.isArray(page.onReachBottom)) {
        page.onReachBottom.push(hook);
      } else {
        page.onReachBottom = [hook];
      }
    });
    return;
    (0, import_uni_app.onReachBottom)(hook);
  };
  const onPageScroll = (hook) => {
    if (!hook)
      return;
    (0, import_vue.onMounted)(() => {
      const page = findPage(_this);
      if (Array.isArray(page.onPageScroll)) {
        page.onPageScroll.push(hook);
      } else {
        page.onPageScroll = [hook];
      }
    });
    return;
    (0, import_uni_app.onPageScroll)(hook);
  };
  return {
    onPageShow,
    onPageHide: import_uni_app.onHide,
    /**
     * 目前在组件中使用该hook时，需要页面onPageScroll有值才会触发。
     * 简单粗暴的办法是全局给mixin一个空函数（支付宝小程序必须加载页面，加全局mixin无效）
     */
    onPageScroll,
    onPageReachBottom,
    pageScrollTo
  };
};
